<template>
	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
		
	  <el-form-item label="采购清单号" prop="pnum" >
	    <el-input v-model="ruleForm.pnum"></el-input>
	  </el-form-item>
	  <el-form-item label="商品编号" prop="gnum" >
	    <el-input v-model="ruleForm.gnum"></el-input>
	  </el-form-item>
	  <el-form-item label="采购数量" prop="dnumber" >
	    <el-input v-model="ruleForm.dnumber"></el-input>
	  </el-form-item>
	  <el-form-item label="商品单价" prop="gprice" >
	    <el-input v-model="ruleForm.gprice"></el-input>
	  </el-form-item>
	  <el-form-item label="商品总价" prop="dprice" >
	    <el-input v-model="ruleForm.dprice"></el-input>
	  </el-form-item>
	  <el-form-item label="备注" prop="dremarks" >
	    <el-input v-model="ruleForm.dremarks"></el-input>
	  </el-form-item>
	 
	  <el-form-item>
	    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
	    <el-button @click="resetForm('ruleForm')">重置</el-button>
	  </el-form-item>
	</el-form>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          pnum: '',
          gnum: '',
          dnumber: '',
          gprice: '',
          dprice: '',
          dremarks: ''
        },
        rules: {
          pnum: [
            { required: true, message: '请输入采购清单号', trigger: 'blur' },
          ],
          gnum: [
            { required: true, message: '请输入商品编号', trigger: 'blur' },
          ],
          dnumber: [
            { required: true, message: '请输入采购数量', trigger: 'blur' },
          ],
          gprice: [
            { required: true, message: '请输入商品单价', trigger: 'blur' },
          ],
          dprice: [
            { required: true, message: '请输入商品总价', trigger: 'blur' },
          ],
          dremarks: [
            { required: true, message: '请输入备注', trigger: 'blur' },
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
		  const _this=this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.put('http://localhost:8181/detail/updateDetail',this.ruleForm).then(function(resp){
				console.log(resp)
				if(resp.data == 'sucess'){
					alert('修改成功')
					_this.$router.push('/DetailManage')
				}
			})
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
	created() {
		const _this=this
		axios.get('http://localhost:8181/detail/findById/'+this.$route.query.dnum).then(function(resp){
			console.log(resp)
			_this.ruleForm=resp.data
		})
	}
  }
</script>


